var cf = require("./config");
var log4js = require("log4js");
var logInfo,logErr;
if(/windows/i.test(process.env.os)&&cf.log4js.terminalPrint){
    logInfo=logErr={};
    function c(){}
    ['info','error'].forEach(function(t){
        logInfo[t]=c;
    })
}else{
    cf.log4js.appenders[0].pattern = 'yyyyMMdd.info'+(process.argv[2]||0)+'.log';
    cf.log4js.appenders[1].pattern = 'yyyyMMdd.error'+(process.argv[2]||0)+'.log';
    log4js.configure(cf.log4js);
    logInfo = log4js.getLogger('log_info');
    logErr = log4js.getLogger('log_error');
}


function makeLogArr(args){
    var info = [];
    for(var i = 0; i < args.length; i++){
        if(args[i]&&typeof args[i]=="object"){
            info.push(JSON.stringify(args[i]));
        }else{
            info.push(args[i] + "");
        }
    }
    return info;
}
exports.errorLog = function(){
    var bk = makeLogArr.call(null, arguments);
    if(bk.length === 0)return ;
    var str = bk.join(" ");
    if(cf.log4js.mixWrite)
        logInfo.error(str);
    logErr.error(str);
    cf.log4js.terminalPrint && console.error("["+new Date()+"] [ERROR]",str);
};

exports.infoLog = function(){
    var bk = makeLogArr.call(null, arguments);
    if(bk.length === 0)return ;
    var str = bk.join(" ");
    logInfo.info(str);
    cf.log4js.terminalPrint && console.log("["+new Date()+"] [INFO]",str);
};